﻿/*-------------------------------------
//
//Copyright (C) 2007 开发二组 版权所有。
//
//文件名：InventoryAdd.ascx.cs
//
//文件功能描述：商品入库管理
// 
//创建标识：2007.11.21 曹骞
//创建描述：
//
//修改标识：2007.11.29 曹骞
//修改描述：增加大类别下拉列表绑定
------------------------------------*/

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using JXMSTC.SmartBusiness.BFL;
using JXMSTC.SmartBusiness.BFL.IBLL;
using JXMSTC.SmartBusiness.BFL.BLLFactory;
using localhost;

/// <summary>
/// 商品入库管理
/// </summary>
public partial class UserControls_InventoryAdd : System.Web.UI.UserControl
{
   /// <summary>
   /// 初始化商品列表
   /// </summary>
   /// <param name="sender"></param>
   /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //获取商品小类别列表
            ProductService Inventoryadd = new ProductService();
            DataSet ds = new DataSet();
            //获取商品大类别列表
            ds = Inventoryadd.GetUpperCategoryList();
            this.dropUpper.DataSource = ds.Tables[0];
            this.dropUpper.DataTextField = ds.Tables[0].Columns[1].ToString();
            this.dropUpper.DataValueField = ds.Tables[0].Columns[0].ToString();

            this.dropUpper.DataBind();
            //有当前大类别获取商品小类别列表
            getLowerCategory();
            //由当前小类别获取商品列表
            getProductList();
           
        }

        
    }

   /// <summary>
   /// 获取异步调用结果，绑定数据源
   /// </summary>
   /// <param name="sender"></param>
   /// <param name="e"></param>
    void InventoryAdd_GetLowCategoryListCompleted(object sender, GetLowCategoryListCompletedEventArgs e)
    {   
        //绑定小类下拉列表
        this.dropCatagories.DataSource = e.Result.Tables[0].Columns[0];
        this.dropCatagories.DataBind();
    } 

    /// <summary>
    /// 商品入库
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnInventoryAdd_Click(object sender, ImageClickEventArgs e)
    {


        //获取方法参数列表
        ProductService Service = new ProductService() ;
        string strLowerCategory = this.dropCatagories.SelectedValue.ToString();
        string strProductName = this.dropProductName.SelectedItem.Text;
        int iProductCount = Convert.ToInt32 (this.txtNumber.Text);
        //获取操作员ID
        int iStaffId=Convert.ToInt32(Session["StaffID"]);
      
        //异步调用商品入库操作方法
        Service.AddInventoryCompleted += new AddInventoryCompletedEventHandler(Service_AddInventoryCompleted);
        Service.AddInventoryAsync(strLowerCategory, strProductName, iProductCount, iStaffId);
       
    }
    /// <summary>
    /// 获取异步调用结果
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void Service_AddInventoryCompleted(object sender, AddInventoryCompletedEventArgs e)
    {  
        
        if (e.Result)
        {  
            //结果不为空时给出添加成功提示
            Page.RegisterStartupScript("warnings", "<script>alert('添加成功！');</script>");  
        }
        else
        {
            //否则提示添加失败
            Page.RegisterStartupScript("warnings", "<script>alert('添加失败.');</script>");
        }
        this.txtNumber.Text = "";
    }
 
    /// <summary>
    /// 取消添加
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
   

    /// <summary>
    /// 由商品类别获取该类别的商品名列表
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dropCatagories_SelectedIndexChanged(object sender, EventArgs e)
    {
       //获取商品名绑定到商品下拉列表
        getProductList();  
    }

    /// <summary>
    /// 获取商品名列表
    /// </summary>
    void  getProductList()
    {
        //实例化一个ProductService对象
        ProductService Service1 = new ProductService();
        string LowCategory = this.dropCatagories.SelectedValue;
        DataSet ds = new DataSet();
        //由当前商品小类别列表获取商品列表
        ds = Service1.GetProductListByLowCategoryID(LowCategory);
        this.dropProductName.DataSource = ds.Tables[0];
        this.dropProductName.DataTextField = ds.Tables[0].Columns[1].ToString();
        this.dropProductName.DataValueField = ds.Tables[0].Columns[0].ToString();
        //绑定数据到下拉列表
        this.dropProductName.DataBind();
    }

    /// <summary>
    ///  获取商品小类别列表 
    /// </summary>
    void getLowerCategory()
    {
        //实例化一个ProductService对象
        ProductService Service2 = new ProductService();
        string UpperCategory = this.dropUpper.SelectedValue;
        DataSet ds = new DataSet();
        //由当前商品大类别列表获取商品小类别
        ds = Service2.GetLowCategoryListByUpperCategoryID(UpperCategory);
        this.dropCatagories.DataSource = ds.Tables[0];
        this.dropCatagories.DataTextField = ds.Tables[0].Columns[2].ToString();
        this.dropCatagories.DataValueField = ds.Tables[0].Columns[0].ToString();
        //绑定数据到下拉列表
        this.dropCatagories.DataBind();
    }

    /// <summary>
    /// 由大类别获取该类别的小类别列表
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dropUpper_SelectedIndexChanged(object sender, EventArgs e)
    {
        //获取商品小类别列表
        getLowerCategory();
        //获取商品列表
        getProductList();
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnInventoryCancel_Click(object sender, ImageClickEventArgs e)
    {
       
        Server.Transfer("~/Manage/Default.aspx");
    }
}

